package com.zenika.zenbinding.sample.client;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.zenika.zenbinding.client.model.ValueModel;
import com.zenika.zenbinding.client.widget.VerticalUserFormPanel;
import com.zenika.zenbinding.sample.model.Category;
import com.zenika.zenbinding.sample.model.Person;

/**
 * This time using a real panel/layout.
 * @author Pierre Queinnec
 */
public class FormulairePanel2 extends VerticalPanel {

	private Person person;
	private List categories;

	public FormulairePanel2() {
		this.setUp();

		VerticalUserFormPanel formPanel = new VerticalUserFormPanel(9);
		formPanel.addTextBox(this.person, "name", "Nom :");
		formPanel.addTextBox(this.person, "firstName", "Prénom :");
		formPanel.addTextBox(this.person, "age", "Age :");
		formPanel.addCheckBox(this.person, "bachelor", "Célibataire :");
		String[] sexes = { "Homme", "Femme" };
		formPanel.addRadioGroup(this.person, "sex", sexes, null, false);
		ValueModel birthdayModel = formPanel.addTextBox(this.person, "birthday", "Date de naissance :");
		TextBox birthdayTB = (TextBox) birthdayModel.getWidget();
		birthdayTB.setMaxLength(10);
		birthdayTB.setVisibleLength(10);

		formPanel.addTextArea(this.person, "comment", "Remarques :");
		formPanel.addListBox(this.person, "category", this.categories, "name", "Catégorie :");
		String[] occupations = { "Etudiant(e)", "Employé(e)" };
		formPanel.addBooleanRadioGroup(this.person, "occupation", occupations, "Occupation", false);

		this.add(formPanel);
	}

	private void setUp() {
		this.categories = new ArrayList();
		this.categories.add(null);
		this.categories.add(new Category("Technicien"));
		this.categories.add(new Category("Agriculteur"));
		this.categories.add(new Category("Cadre"));
		this.categories.add(new Category("Cadre Sup"));

		this.person = new Person("Durand", "Jean-Pierre");
		this.person.setAge(32);
		this.person.setBirthday(new Date());
		this.person.setCategory((Category) this.categories.get(2));
		this.person.setSex("Homme");
		this.person.setOccupation(new Boolean(true));
	}

}
